package com.neusoft.neuiotms.dcom.converter.alter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.alter.AlterCountersignatureApprovalDTO;
import com.neusoft.neuiotms.dcom.model.alter.AlterCountersignatureApproval;
import com.neusoft.neuiotms.dcom.repository.alter.AlterCountersignatureApprovalRepository;

@Component
public class AlterCountersignatureApprovalConverter
        extends AbstractConverter<AlterCountersignatureApproval, AlterCountersignatureApprovalDTO> {

    @Autowired
    private AlterCountersignatureApprovalRepository countersignatureApprovalRepository;

    @Override
    public AlterCountersignatureApproval toModel(final AlterCountersignatureApprovalDTO dto) {
        AlterCountersignatureApproval model;
        if (dto.isNew()) {
            model = new AlterCountersignatureApproval();
        } else {
            model = this.countersignatureApprovalRepository.getOne(dto.getId());
        }

        model.setApprovalComments(dto.getApprovalComments());
        model.setTaskId(dto.getTaskId());
        model.setWorkNum(dto.getWorkNum());
        model.setOperatorCode(dto.getOperatorCode());
        model.setOperatorName(dto.getOperatorName());
        model.setWhetherAgree(dto.getWhetherAgree());
        return model;
    }

    @Override
    public AlterCountersignatureApprovalDTO toDTO(final AlterCountersignatureApproval model,
            final boolean forListView) {

        final AlterCountersignatureApprovalDTO dto = new AlterCountersignatureApprovalDTO();
        dto.setId(model.getId());
        dto.setApprovalComments(model.getApprovalComments());
        dto.setTaskId(model.getTaskId());
        dto.setWorkNum(model.getWorkNum());
        dto.setOperatorCode(model.getOperatorCode());
        dto.setOperatorName(model.getOperatorName());
        dto.setWhetherAgree(model.getWhetherAgree());
        return dto;
    }

}
